package com.woniuxy.commons.service.factory;

import com.woniuxy.commons.Goods;
import com.woniuxy.commons.service.GoodsService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * @author: 15489  <br/>
 * Date: 2022/3/28:14:16  <br/>
 * Description:
 */

//geign 接口的fallback工厂
@Component
public class GoodsServerFactory implements FallbackFactory<GoodsService> {
//    创建接口对象
    @Override
    public GoodsService create(Throwable throwable) {
//        吃出实现的方法就是 openfegin接口中对应方法的allback方法 如果通过openfegin 调用某个方法失败 就会自动调用对象的 fallvback返回结果
        return new GoodsService() {
            @Override
            public List<Goods> all() {
                return Arrays.asList(
                        new Goods(3001,"aaaaa",11)
                );
            }

            @Override
            public Goods find(int id) {
                return null;
            }

            @Override
            public boolean add(Goods goods) {
                return false;
            }

            @Override
            public void updata(Goods goods) {

            }

            @Override
            public void del(int id) {

            }

            @Override
            public String getPort() {
                return "超时";
            }
        };
    }
}
